<template>
	<div>
	  <div align="center">
	    <br>
	    <img src="../assets/demo/person.png"  width="150" height="150">
        <router-link to="/tabbar/myinfo"><div class="season">{{name}}</div></router-link>
	  </div>
  	<div v-show='staff'>
  	  <group>
  	    <cell title="我的积分">
  	    	<span class="demo-icon" slot="icon" style="color:#35495e;">&#xe62f;</span>
  	    </cell>
        <template>
        	<div>
              <card>
                <div slot="content" class="card-demo-flex card-demo-content01">
                  <div class="vux-1px-l vux-1px-r">
                    本季度积分
                    <br/>
                    <span>{{seasonScore}}</span>
                  </div>
                  <div>
                    本月度积分
                    <br/>
                    <span>{{monthScore}}</span>
                  </div>
                </div>
              </card>
          </div>
        </template>
	    </group>
	  <group>
	  	<div>
	    <cell title="我的排名">
	    	<span class="demo-icon" slot="icon" style="color:red;">&#xe630;</span>
	    </cell>
	      <template>
	      	<div>
	            <card>
	              <div slot="content" class="card-demo-flex card-demo-content01">
	                <div class="vux-1px-l vux-1px-r">
	                  上季度排名
	                  <br/>
	                  <span>{{seasonRank}}</span>
	                </div>
	                <div class="vux-1px-r">
	                  本月排名
	                  <br/>
	                  <span>{{seasonRank}}</span>
	                </div>
	              </div>
	            </card>
	        </div>
	      </template>
	    </div>
	  </group>
	</div>
	<div v-show='admin'>
	  <group>
	  	<div>
	    <cell title="暂无信息">
	    	<span class="demo-icon" slot="icon" style="color:#35495e;">&#xe62f;</span>
	    </cell>
	    </div>
	  </group>
	</div>
  </div>
</template>

<script>
import { Cell, CellBox, CellFormPreview, Group, Badge, Card} from 'vux'

export default {
  components: {
    Group,
    Cell,
    CellFormPreview,
    CellBox,
    Badge,
    Card
  },
  data: function () {
    var ms_staffId = localStorage.getItem('ms_staffId')
    return {
      memberlist: [],
      money: null,
      showContent001: false,
      monthScore: '',
      C: '',
      seasonScore: '',
      seasonRank: '',
      monthInfoMap: '',
      seasonInfoMap: '',
      staffIdOnLogin: ms_staffId,
      name: '',
      staff: false,
      admin: false
    }
  },
  mounted: function () {
    this.getAuthority()
  },
  methods: {
    monthInfo: function () {
      var self = this
      self.$ajax({
        method: 'get',
        url: '../wx/user/info',
        params: {
          staffId: self.staffIdOnLogin,
          scoreType: 2
        }
      })
      .then(function (res) {
        self.monthInfoMap = res.data[0]
        if (self.monthInfoMap == null) {
          self.monthScore = '暂无'
          self.monthRank = '暂无'
        } else {
          self.monthScore = self.monthInfoMap.totalScore
          self.monthRank = self.monthInfoMap.rank
        }
      })
      .catch(function (err) {
        console.log(err)
      })
    },
    seasonInfo: function () {
      var self = this
      self.$ajax({
        method: 'get',
        url: '../wx/user/info',
        params: {
          staffId: self.staffIdOnLogin,
          scoreType: 1
        }
      })
      .then(function (res) {
        self.seasonInfoMap = res.data[0]
        if (self.seasonInfoMap == null) {
          self.seasonScore = '暂无'
          self.seasonRank = '暂无'
        } else {
          self.seasonScore = self.seasonInfoMap.totalScore
          self.seasonRank = self.seasonInfoMap.rank
        }
      })
      .catch(function (err) {
        console.log(err)
      })
    },
    getAuthority: function () {
      var self = this
      self.$ajax({
        method: 'get',
        url: '../wx/auth',
        params: {
          staffId: self.staffIdOnLogin
        }
      })
      .then(function (res) {
        console.log(res)
        self.groupType = res.data[0].groupName
        self.name = res.data[0].userName
        if (self.groupType == 'admin') {
          self.admin = true
          self.name = '管理员'
        }else{
          self.staff = true
          self.monthInfo()
          self.seasonInfo()
        }
      })
      .catch(function (err) {
        console.log(err)
      })
    }
  }
}
</script>

<style lang="less">
.card-demo-flex {
  display: flex;
}
.card-demo-content01 {
  padding: 10px 0;
}
.card-demo-flex > div {
  flex: 1;
  text-align: center;
  font-size: 12px;
}
.demo-icon {
  margin-right: 15px;
}
</style>